import { AppModel } from '../../../../model/AppModel'
import { BeLED } from '../../../../model/parts/BeLED'
import { createPartMenu } from '../BlockPackage'

declare var Vue : any


export default {

    category: Blockly.Categories.bepart ,
    
    color: [
        Blockly.Colours.bepart.primary,
        Blockly.Colours.bepart.secondary,
        Blockly.Colours.bepart.tertiary
    ] ,

    previousStatement: true ,
    nextStatement: true ,

    init(model:AppModel) {
        this.appendDummyInput()
            .appendField("LED")
            .appendField(createPartMenu(model, BeLED), 'part')
            
        this.appendValueInput("value")
            .appendField("亮度%")
    } ,

    run (args: any, util: any, runtime: any, model: AppModel) {
    } ,

    coder: {
        JavaScript(block: any, coder: any, model: AppModel) {
            
            // 
            let partUUID = block.getFieldValue('part')
            let part = model.findPartFromUUID(partUUID)
            if(!part)
                return "// unknow LED part uuid: " + partUUID

            let val = coder.valueToCode(block, 'value', coder.ORDER_ASSIGNMENT) || '0'

            return `${coder.indentString()}be.part["${part.instanceName}"].setValue(${val}, true)\n`
        }
    }
}
